package com.siyoumi.app.external_api.aliyun.entity;

import com.siyoumi.app.entity.SysAccsuperZzzApi;
import com.siyoumi.app.modules.accsuper_admin.service.SvcSysAccspuerConfig;
import com.siyoumi.component.XSpringContext;
import com.siyoumi.validator.XValidator;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "alipay-oss")
public class EnvAlipayOss {
    String access_key_id;
    String access_key_secret;
    String bucket_name;
    String bucket_host; //请求域名
    //Bucket所在地域对应的Endpoint。以华东1（杭州）为例，Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
    String endpoint;
    String region;
    //https://api.aliyun.com/product/Sts
    String sts_endpoint;
    String sts_arn; //RAM访问控制->角色
    String dir_name = "app"; //目录

    public static EnvAlipayOss getBean() {
        return XSpringContext.getBean(EnvAlipayOss.class);
    }

    public static EnvAlipayOss getEntityByConfig() {
        SysAccsuperZzzApi apiConfig = SvcSysAccspuerConfig.getBean().getApiEntity("aliyun");
        XValidator.isNull(apiConfig, "未配置阿里云参数");

        EnvAlipayOss config = getBean();
        config.setAccess_key_id(apiConfig.getApi_app_id());
        config.setAccess_key_secret(apiConfig.getApi_app_secret());
        return config;
    }
}
